import 'dart:ffi';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:study1/page/part_view/v1user_list.dart';
import 'package:study1/page/part_view/v1user_part/add_user.dart';

class CartPage extends StatefulWidget {
  const CartPage({Key? key}) : super(key: key);

  @override
  _CartPageState createState() => _CartPageState();
}

class _CartPageState extends State<CartPage> {
  List<String> yonghutitleList = ["用户列表", "添加管理员", "添加用户", "视频会议"];
  List<String> yonghuimagelist = [
    "image/s_userlist.png",
    "image/user_add.png",
    "image/user_add1.png",
    "image/img_huiyi.png"
  ];

  Future _alertDialog() async {
    var result = await showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text("提示信息"),
            content: Text("您确定要删除吗"),
            actions: <Widget>[
              RaisedButton(
                child: Text("取消"),
                color: Colors.blue,
                textColor: Colors.white,
                onPressed: () {
                  print("取消");
                  Fluttertoast.showToast(msg: "你取消了");
                  Navigator.pop(context);
                },
              ),
              RaisedButton(
                child: Text("确定"),
                color: Colors.blue,
                textColor: Colors.white,
                onPressed: () {
                  print("确定");
                  Fluttertoast.showToast(msg: "你确定了");

                  Navigator.pop(context, "ok");
                },
              ),
            ],
          );
        });
    print("result   -- >  " + result);
    return result;
  }

  Void? _yonghulist_click(String title)
  {
    switch(title)
    {
      case "用户列表":{
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => const UserList()));
      }
      break;
      case "添加管理员":{
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => const UserList()));
      }
      break;
      case "添加用户":{
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => const V1user_Add()));
      }
      break;
      case "视频会议":{
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => const UserList()));
      }
      break;
    }

    //return null;

  }

  getGridViewItem(String title, String imageName) {
    return InkWell(
      onTap: ()=> {
        _yonghulist_click(title)
        // Switch(title)
        // {
        //
        // }
      },
      child: Card(
        color: Colors.white54,
        elevation: 1.0, //设置阴影
        shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(20.0))), //设置圆角
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
                  child: Container(
                    padding: const EdgeInsets.only(top: 20),
                    alignment: Alignment.center,
                    child: Image.asset(
                      imageName,
                      width: 40,
                      height: 40,
                      fit: BoxFit.cover,
                    ),
                  ),
                )
              ],
            ),
            Row(
              children: <Widget>[
                Expanded(
                  child: Container(
                      padding: EdgeInsets.only(top: 8),
                      alignment: Alignment.center,
                      child: Text(
                        title,
                        style: const TextStyle(
                            color: Colors.grey, fontSize: 9, height: 1.2),
                      )),
                )
              ],
            )
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("系统管理"),
      ),
      body: Column(
        children: <Widget>[
          Row(
            children: [Text("用户管理 ")],
          ),
          Row(
            children: [
              Container(
                decoration: const BoxDecoration(
                  // border: Border.all(), //边框
                  // color: Colors.cyan, //背景色
                  // borderRadius: BorderRadius.circular(20) //圆角
                ),
                 height: ScreenUtil().setHeight(160),
                width: ScreenUtil().setWidth(750),
                // padding: const EdgeInsets.all(3.0),
                child: GridView.builder(
                    padding: const EdgeInsets.all(1.0),
                    itemCount: yonghutitleList.length,
                    gridDelegate:
                        const SliverGridDelegateWithFixedCrossAxisCount(
                            //横轴元素个数
                            crossAxisCount: 4,
                            //纵轴间距
                            mainAxisSpacing: 2.0,
                            //横轴间距
                            crossAxisSpacing: 2.0,
                            //子组件宽高长度比例
                            childAspectRatio: 1.0),
                    itemBuilder: (BuildContext context, int index) {
                      return getGridViewItem(
                          yonghutitleList[index], yonghuimagelist[index]);
                    }),
              )
            ],
          ),
          Row(
            children: [
              InkWell(
                  onTap: () => Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => const UserList())),
                  child: Container(
                    width: ScreenUtil().setWidth(750),
                    height: ScreenUtil().setHeight(50),
                    color: Colors.teal,
                    child: const Text("单位管理"),
                  )),
            ],
          ),
        ],
      ),
    );
  }
}
